<template>
  <div class="drinkMachindRecord">
    <!-- <c-title :hide="false" text="历史用水情况"></c-title> -->
    <div class="desc">
      <backBtn :icon='true'></backBtn>
      历史用水情况</div>
    <div class="list">
      <template v-if="listData.length > 0">
        <div class="lis" v-for="(item, index) in listData" :key="index">
          <div class="lis_t">
            <div class="date">{{ item.day }}</div>
            <div class="Id">ID:{{ item.id }}</div>
          </div>
          <div class="lis_b">单日用水量：{{ item.day_water }}L</div>
        </div>
      </template>
      <template v-else>
        <van-empty image="search" description="暂无更多" />
      </template>
    </div>
  </div>
</template>
<script>
import { scrollMixin } from "../../utils/mixin"; //引入加载更多
import backBtn from './components/backBtn.vue'
export default {
  mixins: [scrollMixin],
  data() {
    return {
      listData: [],

      page: 1,
      total_page: 0,
      isLoadMore: true
    };
  },
  components:{backBtn},
  activated() {
    this.getData();
  },
  methods: {
    getData() {
      $http.post("plugin.drink-machine.frontend.machine.waterLogList", { machine_id: this.$route.params.id }, "加载中...").then(res => {
        if (res.result == 1) {
          console.log(res.data);
          this.isLoadMore = true;
          this.listData = res.data.data;
          this.total_page = res.data.last_page;
          if (!this.total_page) {
            this.total_page = 0;
          }
        } else {
          this.$toast(res.msg);
        }
      });
    },
    getMoreData() {
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.page >= this.totalPage) {
        return;
      } else {
        this.page += +1;
        $http.post("plugin.drink-machine.frontend.machine.waterLogList", { machine_id: this.$route.params.id, page: this.page }, "正在获取").then(response => {
          if (response.result == 1) {
            let list = response.data.data;
            this.listData = [...this.listData, ...list];
          } else {
            this.page = this.page - 1;
            this.isLoadMore = false;
            this.$dialog.alert({ message: response.msg });
          }
        });
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.desc {
  margin: 0.84rem 0.75rem;
  font-size: 0.94rem;
  text-align: left;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.list {
  margin: 0 0.75rem;

  .lis {
    margin-top: 0.5rem;
    background: #fff;
    border-radius: 0.75rem;
    padding: 0.88rem 0.75rem;
    display: flex;
    flex-direction: column;
    justify-content: center;

    .lis_b {
      text-align: left;
    }

    .lis_t {
      margin-bottom: 0.5rem;
      display: flex;
      justify-content: space-between;

      .date {
        font-weight: bold;
        font-size: 0.94rem;
        color: #00001c;
        flex-shrink: 0;
        margin-right: 2rem;
      }

      .Id {
        flex: 1;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        text-align: right;
        font-size: 0.81rem;
      }
    }
  }
}
</style>
